/**  
 * All rights Reserved, Designed By www.woniuxy.com
 * @Title:  Account.java   
 * @Package com.woniu.domain   
 * @Description:    Description  
 * @author: 蜗牛学院  
 * @date:   2019年7月31日 下午3:50:45
 * @user:   Administrator  
 * @version V1.0 
 * @Copyright: 2019 www.woniuxy.com Inc. All rights reserved. 
 * 注意：本内容仅限于成都蜗牛创想科技有限公司，禁止外泄以及用于其他的商业目
 */ 
package com.woniu.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.woniu.dao.CategoryDao;
import com.woniu.dao.impl.CategoryDaoImpl;
import com.woniu.domain.Category;
import com.woniu.domain.Goods;
import com.woniu.service.CategoryService;
import com.woniu.service.bo.PageBean;

/**
 * @author Administrator
 *
 */
public class CategoryServiceImpl implements CategoryService {
CategoryDao cd = new CategoryDaoImpl();
	@Override
	public List<Category> getCategoryInfo() throws SQLException {
		
		return cd.getCategoryInfo();
	}
	@Override
	public PageBean listGoodsByCategory(Integer cId, Integer currentPage) throws SQLException {
		PageBean pb = new PageBean();
		//每页十条数据
		pb.setPageSize(10);
		//拿到分页名称
		Category c = cd.getGoodsCategory(cId);
		pb.setCategory(c);
		//设置当前页
		pb.setCurrentPage(currentPage);
		//设置数据源
		pb.setGoodsList(cd.listGoodsByCategory(cId,currentPage,pb.getPageSize()));
		//获取所有商品数量
		int count = cd.getGoodsCount(cId);
		pb.setTotalSize(count);
		//--设置总页数
		pb.setTotalPage(count % pb.getPageSize()==0?count/pb.getPageSize():count/pb.getPageSize()+1);
		
		return pb;
	}
	@Override
	public Goods findGoodsBygId(Integer gId) throws SQLException {
		
		return cd.getGoodsInfo(gId);
	}

}
